/**
 * @param {string} text source text
 * @return {DataView} decoded binary buffer
 */
function decodeHexString(text) {
    const buffer = new Uint8Array(text.length / 2);
    for (let i = 0; i < text.length / 2; i++) {
        buffer[i] = parseInt(text.substring(i * 2, 2), 16);
    }

    // console.log(new DataView(buffer.buffer), 'new DataView(buffer.buffer)==================');
    return new DataView(buffer.buffer);
}

/**
 * @param {string | ArrayBuffer | ArrayBufferView} source source
 * @return {DataView} data view
 */
function getDataView(source) {
    if (typeof source === 'string') {
        return decodeHexString(source);
    }
    if (ArrayBuffer.isView(source)) {
        if (source instanceof DataView) {
            return source;
        }
        return new DataView(source.buffer, source.byteOffset, source.byteLength);
    }
    if (source instanceof ArrayBuffer) {
        return new DataView(source);
    }
    return null;
}

